
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>后台</title>

    <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-switch.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
</head>

<body>

<include file="Common/topNav" />

<div class="container-fluid">
    <div class="row">
        <include file="Common/leftMenu" />
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="cont-title clearfix">
                <div class="title">工位列表</div>
                <div class="btn-group">
                    <button class="btn" type="button" id="add_station">添加</button>
                    <button class="btn" type="button" id="del_station">删除</button>
                </div>
            </div>
            <include file="search_station" />
            <div class="table-responsive">
                <table class="table table-striped table-hover" id="tableData">
                    <thead>
                    <tr>
                        <th>
                            <input type="checkbox" id="checkAll" />
                        </th>
                        <th>序号</th>
                        <th>工位编号</th>
                        <th>工位价格（元/月）</th>
                        <th>是否有效</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <empty name="stationList">
                        <tr>
                            <td colspan="10">没有相关记录</td>
                        </tr>
                    </empty>
                    <foreach name="stationList" item="station">
                        <tr>
                            <td>
                                <input type="checkbox" name="station_check[]" value="{$station.id}" />
                            </td>
                            <td>{$key|getLineNum=$nowPage,$pageSize}</td>
                            <td>
                                <if condition="$station['room']['room_no']">
                                    {$station.space.name} - {$station.room.room_no} - {$station.station_no}&nbsp;
                                    <span class="label label-primary">独</span>
                                <else/>
                                    {$station.space.name} - {$station.station_no}&nbsp;
                                    <span class="label label-warning">开</span>
                                </if>
                            </td>
                            <td>{$station.unit_price|number_format=2}</td>
                            <td>
                                <if condition="$station.status eq 1">
                                    <span class="label label-success">是</span>
                                <else/>
                                    <span class="label label-danger">否</span>
                                </if>
                            </td>
                            <td>{$station.create_time|date="Y-m-d H:i",###}</td>
                            <td>
                                <a thisId="{$station.id}" href="javascript:void(0);" class="station_detail">查看详情</a>
                                | <a thisId="{$station.id}" href="javascript:void(0);" class="station_edit">修改</a>
                                | <a thisId="{$station.id}" href="javascript:void(0);" class="station_del">删除</a>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <div class="page">
                    {$page}
                </div>
            </div>
        </div>
    </div>
</div>


<include file="Common/modalHtmls" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-switch.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript">
    var roomId = "{$room_id}";
    console.log(roomId);
    $(function(){
        $("input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_flat-blue',
            radioClass: 'iradio_flat-blue',
            increaseArea: '10%'
        });
        $("#add_station").bind("click",addStation);
        $("#del_station").bind("click",delStationBatch);
        $("#tableData .station_detail").click(function(){
            showStation(this);
        });
        $("#tableData .station_edit").click(function(){
            editStation(this);
        });
        $("#tableData .station_del").click(function(){
            delStation(this);
        });
        chooseAll();
        $("#search_space_id").bind("change",chooseOffice);
        $("#search_space_id").change();
    });

    function chooseAll(){
        $('#checkAll').on('ifChecked', function(event){
            $("input[name='station_check[]']:checkbox").each(function(){
                var $this = $(this);
                if(!$this.prop("disabled")){
                    $this.iCheck("check");
                }
            });
        });
        $('#checkAll').on('ifUnchecked', function(event){
            $("input[name='station_check[]']:checkbox").iCheck("uncheck");
        });
    }

    function addStation(){
        common.loading('正在加载...');
        common.htmlAjax("{:U('Admin/Space/Spaces/addStation')}", {}, function (html) {
            common.closeLoading();
            if(common.isJsonString(html)){
                var error = JSON.parse(html);
                if (error.info){
                    common.alert("提示",error.info);
                }
                return;
            }
            $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
        });
    }

    function delStationBatch(){
        var str = "";
        $("input[name='station_check[]']:checkbox").each(function(){
            if(true == $(this).is(':checked')){
                str += "," + $(this).val();
            }
        });
        if(str == ""){
            common.alert("提示","请至少选择一条记录");
            return;
        }
        common.confirm("提示","确认删除选中的工位吗？",function(){
            str = str.substring(1);
            var param = {id:str};
            $.ajax({
                url: "{:U('Admin/Space/Spaces/deleteStation')}",
                type: "post",
                dataType: "json",
                data: param,
                success: function (data) {
                    if(data.status){
                        common.alert("提示","工位已成功删除!",function(){
                            common.reload();
                        });
                    } else if (data.info){
                        common.alert("提示",data.info);
                    }
                }
            });
        });
    }

    function showStation(obj){
        var id = $(obj).attr("thisId");
        common.loading('正在加载...');
        common.htmlAjax("{:U('Admin/Space/Spaces/detailStation')}", {id:id}, function (html) {
            common.closeLoading();
            if(common.isJsonString(html)){
                var error = JSON.parse(html);
                if (error.info){
                    common.alert("提示",error.info);
                }
                return;
            }
            $("#commonModal").html(html).modal('toggle');
        });
    }

    function editStation(obj){
        var id = $(obj).attr("thisId");
        common.loading('正在加载...');
        common.htmlAjax("{:U('Admin/Space/Spaces/addStation')}", {id:id}, function (html) {
            common.closeLoading();
            if(common.isJsonString(html)){
                var error = JSON.parse(html);
                if (error.info){
                    common.alert("提示",error.info);
                }
                return;
            }
            $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
        });
    }

    function delStation(obj){
        common.confirm("提示","确认删除该工位吗？",function(){
            var id = $(obj).attr("thisId");
            var param = {id:id};
            $.ajax({
                url: "{:U('Admin/Space/Spaces/deleteStation')}",
                type: "post",
                dataType: "json",
                data: param,
                success: function (data) {
                    if(data.status){
                        common.alert("提示","工位已成功删除!",function(){
                            common.reload();
                        });
                    } else if (data.info){
                        common.alert("提示",data.info);
                    }
                }
            });
        });
    }

    function chooseOffice() {
        var spaceId = $(this).val();
        $("#search_room_id").empty();
        $.ajax({
            url: "{:U('Admin/Space/Spaces/getOfficeRoomBySpaceId')}",
            type: "post",
            dataType: "json",
            data: {space_id: spaceId},
            success: function (data) {
                var html = '<option value="">全部</option><option value="0" '+((roomId == "0") ? " selected" : "")+'>开放工位</option>';
                $.each(data,function (index,item) {
                    var selected = (roomId == item.id) ? " selected" : "";
                    html += '<option value="'+item.id+'" '+selected+'>'+item.room_no+'</option>';
                });
                $("#search_room_id").html(html).change();
            }
        });
    }
</script>
</body>
</html>
